package org.lego.biz.task.management.base.service;

import org.lego.biz.task.management.base.entity.Project;
import org.lego.biz.task.management.base.repository.ProjectRepository;
import org.lego.jpa.base.repository.BaseRepository;
import org.lego.jpa.base.service.BaseService;
import org.lego.jpa.base.util.DynamicSpecifications;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by hr.qjy on 16/11/15.
 */
@Service
public class ProjectService extends BaseService<Project, String> {

    @Autowired
    private ProjectRepository projectRepository;

    @Override
    protected BaseRepository<Project, String> getRepository() {
        return projectRepository;
    }

    /**
     * 根据id查询未删除的项目
     *
     * @param id
     * @return
     */
    public Project findOneNormal(String id) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("EQ_status", Project.STATUS_NORMAL);
        params.put("EQ_id", id);
        Specification<Project> specification = DynamicSpecifications.buildSpecification(params, Project.class);
        return projectRepository.findOne(specification);
    }

}
